<!-- Author: Moe Kyaw Thu Aung --> 
<!-- Last Modified: 11 Sep 2012 -->
<?php
	session_start();
	
	include("../confs/config.php");
	
	if(!$_SESSION['auth']) {
		$_SESSION['msg'] = "Please login first!";
		header("location: index.php");
		exit(0);
	}
?>

<html>
	<head>
		<title>My Book Store : Administration</title>
		<link rel="stylesheet" href="../css/admin.css" />
	</head>
	<body>
		<div id="wrapper">
			<div id="head">
				<h1>My Book Store : Order List</h1>
				<a href="actions.php?do=logout">Logout</a>
			</div>

			<div id="order-list">
				
				<a class="tab" href="list.php">Item List</a> 
				<a class="tab this" href="order.php">Order List</a>
				<a class="tab" href="report.php">Feedback</a>
				
				<table width="100%" cellpadding="8" cellspacing="0">
					
					<?php
						$conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
						mysql_select_db($DB_NAME, $conn);
						
						$result = mysql_query("SELECT * FROM orders");
						
						$i = 0;
						while($row = mysql_fetch_assoc($result)) {
							$id = $row['id'];
							
							if($i % 2) $class = "even";
							else $class = "odd";
							
							echo "<tr class='$class'><td valign='top'>";
							
							echo "<div class='customer'>";
							echo "<div class='customer-name'>" . $row['name'] . "</div>";
							echo "<div class='customer-email'>" . $row['email'] . "</div>";
							echo "<div class='customer-phone'>" . $row['phone'] . "</div>";
							echo "<div class='customer-address'>" . $row['address'] . "</div>";
							echo "</div>";
							
							echo "</td><td valign='top'>";
							
							echo "<div class='order-item'>";
							
							$items = mysql_query("SELECT o.qty, i.name FROM order_items AS o LEFT JOIN items AS i ON o.item_id = i.id WHERE o.order_id=$id");
							while($item = mysql_fetch_assoc($items)) {
								echo "<div class='item-name'>" . $item['name'] . " <span>(" . $item['qty'] . ")</span></div>";
							}
							
							echo "</div>";
							
							echo "</td></tr>";
							
							$i++;
						}
					?>
					
				</table>
				
			</div>
			
			<br /><br /><br />
			
			<div id="foot">
				&copy; OneStop JCU.
			</div>

		</div>
	</body>
</html>
